home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 April / CHIP 1996 aprilis (CD06).zip / CHIP_CD06.ISO / sac / pack / lha211_s.exe / SHUF_.ASM < prev    next >
Assembly Source File  |  1991-03-03  |  6KB  |  397 lines

  1. ;***********************************************
  2. ;    shuf_.asm -- extract static Huffman coding
  3. ;***********************************************
  4.             page    0, 128
  5.  
  6. include    amscls.inc
  7. $_init    GEN
  8.  
  9. CGROUP    GROUP    TEXT
  10. DGROUP    GROUP    DATA,BSS
  11.  
  12. TEXT    segment byte public 'CODE'
  13.         assume    cs:CGROUP, ds:DGROUP, ss:DGROUP
  14. TEXT    ends
  15.  
  16. DATA    segment byte public 'DATA'
  17. DATA    ends
  18.  
  19. BSS        segment byte public 'DATA'
  20. np_        dw        1 dup (?)
  21. BSS        ends
  22.  
  23. TEXT    segment byte public 'CODE'
  24.         assume    cs:CGROUP, ds:DGROUP, ss:DGROUP
  25.  
  26. ;
  27. ;void decode_start_st0(void)
  28. ;
  29.  
  30.         public    decode_start_st0_
  31. decode_start_st0_:
  32.         mov        word ptr DGROUP:[n_max_], 286
  33.         mov        word ptr DGROUP:[maxmatch_], 0100h
  34.         call    init_getbits_
  35.         mov        word ptr DGROUP:[np_], 128
  36.         mov        blocksize, 0
  37.         ret
  38.  
  39.  
  40. ;
  41. ;void encode_p_st0(unsigned short j)
  42. ;
  43.  
  44.         public    encode_p_st0_
  45. encode_p_st0_:
  46.         push    cx
  47.         push    ax
  48.         mov        bx, ax
  49.         mov        cl, 6
  50.         shr        bx, cl
  51.         mov        al, pt_len_[bx]
  52.         shl        bx, 1
  53.         mov        bx, pt_code_[bx]
  54.         call    putcode_
  55.         mov        al, 6
  56.         pop        bx
  57. ;        and        bx, 3fh
  58.         call    putbits_
  59.         pop        cx
  60.         ret
  61. TEXT    ends
  62.  
  63. DATA    segment byte public 'DATA'
  64.         public    fixed_
  65. fixed_        db        3
  66.             db        1
  67.             db        4
  68.             db        12
  69.             db        24
  70.             db        48
  71.             db        0
  72.  
  73. fixed1_        db        2
  74.             db        1
  75.             db        1
  76.             db        3
  77.             db        6
  78.             db        13
  79.             db        31
  80.             db        78
  81.             db        0
  82. DATA    ends
  83.  
  84. TEXT    segment byte public 'CODE'
  85.         assume    cs:CGROUP, ds:DGROUP, ss:DGROUP
  86.  
  87. ;
  88. ;static void ready_made(int method)
  89. ;
  90.  
  91.         public    ready_made_
  92. ready_made_:
  93.     push    cx
  94.     push    dx
  95.     push    si
  96.     push    di
  97.     cld
  98.     mov        si, offset DGROUP:fixed_
  99.     $_if <or ax, ax>, NZ
  100.         mov        si, offset DGROUP:fixed1_
  101.     $_endif
  102.     mov        cl, [si]
  103.     inc        si
  104.     xor        ax, ax
  105.     mov        dx,    ax
  106.     mov        ch, al
  107.     stc
  108.     rcr        dx, cl
  109.     mov        bx, offset DGROUP:pt_len_
  110.     mov        di, offset DGROUP:pt_code_
  111.     $_do
  112.         $_while <cmp [si], ch>, E
  113.             inc        cx
  114.             inc        si
  115.             shr        dx, 1
  116.         $_enddo
  117.         mov        [bx], cl
  118.         inc        bx
  119.         stosw
  120.         add        ax, dx
  121.         inc        ch
  122.     $_until <cmp ch, byte ptr np_>, AE
  123.     pop        di
  124.     pop        si
  125.     pop        dx
  126.     pop        cx
  127.     ret
  128.  
  129.  
  130. ;
  131. ;void encode_start_fix(void)
  132. ;
  133.  
  134.         public    encode_start_fix_
  135. encode_start_fix_:
  136.     mov        word ptr DGROUP:[n_max_], 314
  137.     mov        word ptr DGROUP:[maxmatch_], 60
  138.     mov        word ptr DGROUP:[np_], 64
  139.     call    init_putbits_
  140.     call    start_c_dyn_
  141.     xor        ax, ax
  142.     call    ready_made_
  143.     ret
  144.  
  145.  
  146. ;
  147. ;static void read_tree_c(void)    /* read tree from file */
  148. ;
  149.  
  150. read_tree_c_:
  151.     push    cx
  152.     push    dx
  153.     push    di
  154.     cld
  155.     push    ds
  156.     pop        es
  157.     mov        di, offset DGROUP:c_len_
  158.     mov        cx, 3
  159.     $_while <TRUE>
  160.         $_do
  161.             mov        al, 1
  162.             call    getbits_
  163.             $_if <or ax, ax>, NZ
  164.                 mov        al, 4
  165.                 call    getbits_
  166.                 inc        ax
  167.             $_endif
  168.             stosb
  169.         $_until <LOOP>
  170.         $_break , <cmp di, offset DGROUP:c_len_ + 286>, AE
  171.         $_if <cmp al, 1>, E, AND
  172.         $_c  <cmp word ptr -3[di], 0101h>, E
  173.             xor        ax, ax
  174.             mov        cx, 286
  175.             sub        di, 3
  176.             rep        stosb
  177.             mov        ax, 9
  178.             call    getbits_
  179.             mov        cx, 4096
  180.             mov        di, offset DGROUP:c_table_
  181.             rep        stosw
  182.             jmp        retRT_c_
  183.         $_endif
  184.         mov        cx, 286 - 3
  185.     $_enddo
  186.     mov        ax, 286
  187.     mov        bx, offset DGROUP:c_len_
  188.     mov        cx, 12
  189.     mov        dx, offset DGROUP:c_table_
  190.     call    make_table_
  191. retRT_c_:
  192.     pop        di
  193.     pop        dx
  194.     pop        cx
  195.     ret
  196.  
  197. ;
  198. ;static void read_tree_p(void)    /* read tree from file */
  199. ;
  200.  
  201. read_tree_p_:
  202.     push    cx
  203.     push    dx
  204.     push    di
  205.     cld
  206.     push    ds
  207.     pop        es
  208.     mov        di, offset DGROUP:pt_len_
  209.     mov        cx, 3
  210.     $_while <TRUE>
  211.         $_do
  212.             mov        al, 4
  213.             call    getbits_
  214.             stosb
  215.         $_until <LOOP>
  216.         $_break , <cmp di, offset DGROUP:pt_len_ + 128>, AE
  217.         $_if <cmp al, 1>, E, AND
  218.         $_c  <cmp word ptr -3[di], 0101h>, E
  219.             xor        ax, ax
  220.             mov        cx, 128
  221.             sub        di, 3
  222.             rep        stosb
  223.             mov        cx, 4096
  224.             mov        di, offset DGROUP:pt_table_
  225.             rep        stosw
  226.             jmp        retRT_p_
  227.         $_endif
  228.         mov        cx, 128 - 3
  229.     $_enddo
  230. retRT_p_:
  231.     pop        di
  232.     pop        dx
  233.     pop        cx
  234.     ret
  235.  
  236.  
  237. ;
  238. ;void decode_start_fix(void)
  239. ;
  240.  
  241.         public    decode_start_fix_
  242. decode_start_fix_:
  243.     push    cx
  244.     push    dx
  245.     mov        n_max_, 314
  246.     mov        maxmatch_, 60
  247.     call    init_getbits_
  248.     mov        np_, 64
  249.     call    start_c_dyn_
  250.     xor        ax, ax
  251.     call    ready_made_
  252.     mov        ax, np_
  253.     mov        bx, offset DGROUP:pt_len_
  254.     mov        cx, 8
  255.     mov        dx, offset DGROUP:pt_table_
  256.     call    make_table_
  257.     pop        dx
  258.     pop        cx
  259.     ret
  260. TEXT    ends
  261.  
  262. DATA    segment byte public 'DATA'
  263. blocksize    dw        0
  264. DATA    ends
  265.  
  266.  
  267.  
  268. TEXT    segment byte public 'CODE'
  269.         assume    cs:CGROUP, ds:DGROUP, ss:DGROUP
  270.  
  271. ;
  272. ;ushort decode_c_st0(void)
  273. ;
  274.  
  275.         public    decode_c_st0_
  276. decode_c_st0_:
  277.     push    cx
  278.     push    si
  279.     $_if <sub blocksize, 1>, C
  280.         push    dx
  281.         mov        al, 16
  282.         call    getbits_
  283.         dec        ax
  284.         mov        blocksize, ax
  285.         call    read_tree_c_
  286.         mov        al, 1
  287.         call    getbits_
  288.         $_if <or ax, ax>, NZ
  289.             call    read_tree_p_
  290.         $_else
  291.             mov        ax, 1
  292.             call    ready_made_
  293.         $_endif
  294.         mov        ax, 128
  295.         mov        bx, offset DGROUP:pt_len_
  296.         mov        cx, 8
  297.         mov        dx, offset DGROUP:pt_table_
  298.         call    make_table_
  299.         pop        dx
  300.     $_endif
  301.     mov        bx, bitbuf_
  302.     mov        cl, 4
  303.     shr        bx, cl
  304.     shl        bx, 1
  305.     mov        si, c_table_[bx]
  306.     $_if <cmp si, 286>, B
  307.         mov        al, c_len_[si]
  308.         call    fillbuf_
  309.     $_else
  310.         mov        al, 12
  311.         call    fillbuf_
  312.         mov        ax, bitbuf_
  313.         $_do
  314.             $_if <shl ax, 1>, C
  315.                 mov        si, right_[si]
  316.             $_else
  317.                 mov        si, left_[si]
  318.             $_endif
  319.         $_until <cmp si, 286>, B
  320.         mov        al, c_len_[si]
  321.         sub        al, 12
  322.         call    fillbuf_
  323.     $_endif
  324.     $_if <cmp si, 285>, E
  325.         mov        al, 8
  326.         call    getbits_
  327.         add        si, ax
  328.     $_endif
  329.     mov        ax, si
  330.     pop        si
  331.     pop        cx
  332.     ret
  333.  
  334.  
  335. ;
  336. ;ushort decode_p_st0(void)
  337. ;{
  338.  
  339.         public    decode_p_st0_
  340. decode_p_st0_:
  341.     push    cx
  342.     push    si
  343.     mov        bl, byte ptr bitbuf_ + 1
  344.     xor        bh, bh
  345.     shl        bx, 1
  346.     mov        si, pt_table_[bx]
  347.     $_if <cmp si, np_>, B
  348.         mov        al, pt_len_[si]
  349.         call    fillbuf_
  350.     $_else
  351.         mov        al, 8
  352.         call    fillbuf_
  353.         mov        ax, bitbuf_
  354.         $_do
  355.             $_if <shl ax, 1>, C
  356.                 mov        si, right_[si]
  357.             $_else
  358.                 mov        si, left_[si]
  359.             $_endif
  360.         $_until <cmp si, np_>, B
  361.         mov        al, pt_len_[si]
  362.         sub        al, 8
  363.         call    fillbuf_
  364.     $_endif
  365.     mov        al, 6
  366.     mov        cl, al
  367.     call    getbits_
  368.     shl        si, cl
  369.     add        ax, si
  370.     pop        si
  371.     pop        cx
  372.     ret
  373.  
  374.         EXTRN    init_putbits_:near
  375.         EXTRN    putbits_:near
  376.         EXTRN    fillbuf_:near
  377.         EXTRN    make_table_:near
  378.         EXTRN    start_c_dyn_:near
  379.         EXTRN    getbits_:near
  380.         EXTRN    init_getbits_:near
  381.         EXTRN    putcode_:near
  382.  
  383. TEXT    ends
  384.  
  385.         EXTRN    c_table_:word
  386.         EXTRN    c_len_:byte
  387.         EXTRN    pt_table_:word
  388.         EXTRN    pt_code_:word
  389.         EXTRN    pt_len_:byte
  390.         EXTRN    right_:word
  391.         EXTRN    left_:word
  392.         EXTRN    maxmatch_:word
  393.         EXTRN    n_max_:word
  394.         EXTRN    bitbuf_:word
  395.  
  396.         END
  397.